找传奇、传世资源到传世资源站!

delphi封装的回调函数

8.5玩家评分(1人评分)
下载后可评
介绍 评论 失效链接反馈

【例子介绍】

delphi封装的回调函数DLL,为了自动触发事件

【相关图片】

from clipboard

【源码结构】

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;

type
THDProcedure=procedure(s:string); stdcall;
Ttest = function (RecvBack:THDProcedure):integer;StdCall;

TForm1 = class(TForm)
    Button2: TButton;
    Button1: TButton;
    procedure FormCreate(Sender: TObject);
    procedure Button2Click(Sender: TObject);
    procedure Button1Click(Sender: TObject);
private
    { Private declarations }
public
    { Public declarations }
end;

var
Form1: TForm1;
DLLHandle:THandle;
procedure HdProExample(sExam:string);stdcall;
         function test(device:pointer):integer;stdcall;external 'PDLL.dll'; //静态

implementation

{$R *.dfm}
procedure HdProExample(sExam:string);stdcall;
begin
ShowMessage(sExam);
end;

procedure TForm1.FormCreate(Sender: TObject);
begin
//DLLHandle   :=   LoadLibrary(PChar('PDLL.dll'));
end;

procedure TForm1.Button2Click(Sender: TObject);
var
D:   String;
Func:   Ttest;
begin
@Func   :=   GetProcAddress(DLLHandle,   'test');
if   Assigned(@Func)   then
begin
    Func(@HdProExample);
end;
end;

procedure TForm1.Button1Click(Sender: TObject);
begin
test(@HdProExample);
end;

end.


评论

发表评论必须先登陆, 您可以 登陆 或者 注册新账号 !


在线咨询: 问题反馈
客服QQ:174666394

有问题请留言,看到后及时答复